import { OneOf, PromiseResponse } from '@/types/type'
import createAxios from '@/utils/request'
import { AxiosResponse } from 'axios'
import { DownloadFileType } from './type'
import { UploadRawFile } from 'element-plus'

/* eslint-disable no-unused-vars */
enum API {
    UPLOAD_FILE = '/File/UploadFile',
    DOWNLOAD_FILE = '/File/DownloadFile',
}
/**
 * 上传
 * @param file 文件
 * @returns
 */
export const uploadFile = (file: UploadRawFile): PromiseResponse<any> =>
    createAxios({ headers: { 'Content-Type': 'multipart/form-data' } }).request({ url: API.UPLOAD_FILE, method: 'POST', data: { file } })

/**
 * 下载
 * @param file 下载的参数
 * @returns
 */
export const downloadFile = (file: OneOf<DownloadFileType>): Promise<AxiosResponse<any>> => {
    return createAxios({ responseType: 'blob' }).request({ url: API.DOWNLOAD_FILE, method: 'POST', data: file })
}
